﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Noftware.Com.Cryptography
{
    /// <summary>
    /// Cryptography settings.
    /// </summary>
    public class CryptographySettings
    {
        /// <summary>
        /// Encryption or decryption.
        /// </summary>
        public Mode Mode;

        /// <summary>
        /// Type of cryptography.
        /// </summary>
        private CryptographyType _cryptographyType;

        /// <summary>
        /// Type of cryptography.
        /// </summary>
        public CryptographyType CryptographyType
        {
            get { return _cryptographyType; } 
            set 
            { 
                _cryptographyType = value;
                this.SaltRequirement = GetSaltRequirement(value);
            } 
        }

        /// <summary>
        /// Cryptography input.
        /// </summary>
        public string Input;

        /// <summary>
        /// String key for MD5 and Rijndael.
        /// </summary>
        public string StringKey;

        /// <summary>
        /// Numeric key for XOR.
        /// </summary>
        public int NumericKey;

        /// <summary>
        /// Salt requirement, based on specified CryptographyType.
        /// </summary>
        public SaltRequirement SaltRequirement { get; private set; }

        /// <summary>
        /// Get the requirement of the salt based on the specified cryptography type.
        /// </summary>
        /// <param name="type">Cryptography type.</param>
        /// <returns>Salt requirement.</returns>
        public static SaltRequirement GetSaltRequirement(CryptographyType type)
        {
            switch (type)
            {
                case CryptographyType.Rijndael:
                case CryptographyType.Md5:
                    {
                        return SaltRequirement.Required;
                    }
                case CryptographyType.Hex:
                    {
                        return SaltRequirement.NotPermitted;
                    }
                case CryptographyType.Xor:
                    {
                        return SaltRequirement.RequiredIntegerOnly;
                    }
            }

            return SaltRequirement.Required;
        }

    }
}
